package pdm.traj.entity;

import java.util.NoSuchElementException;
import java.util.StringTokenizer;

import pdm.traj.data.TrackPoint;

public class TrackPoint2 extends TrackPoint {
	private String id;
	
	public TrackPoint2(String id, String date, String time, String name,String lacid,String cellid,double lng,double lat, int eventType){
		super(name, lacid, cellid, lng, lat, eventType);
		this.date = date;
		this.time = time;
		this.id = id;
	}

	public TrackPoint2() {
	}

	public int getCellIdInt() {
		return Integer.parseInt(lacid + cellid);
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public String getStationId() {
		return lacid + cellid;
	}
	
	public String getTs() {
		return date + " " + time;
	}
		
	public static TrackPoint2 parseTP(String s) {
		StringTokenizer st = new StringTokenizer(s, ",", false);
		try {
			String ts = st.nextToken();
			String id = st.nextToken();
//			String lng = "";
//			String lat = "";
//			String lng = st.nextToken();
//			String lat = st.nextToken();
			String eventType = st.nextToken();
			String lacid = st.nextToken();
			String cellid = st.nextToken();
			TrackPoint2 tp2 = new TrackPoint2(id, ts.substring(0, 10), ts.substring(11, 19), 
					null, lacid, cellid, 
					-1.0, -1.0, Integer.parseInt(eventType));
//					Double.parseDouble(lng), Double.parseDouble(lat), Integer.parseInt(eventType));
			return tp2;
		} catch (NoSuchElementException nsee) {
			nsee.printStackTrace();
			return null;
		}
	}
	
	@Override
	public String toString() {
		return "tp: " + "id-" + id + "\tdate-" + date + "\ttime-" + time + "\tlng-" + lng
		+ "\tlat-" + lat + "\tlacid-" + lacid + "\tcellid-" + cellid + "\teventType-" + eventType; 
	}
	
	public boolean isBadTP() {
		if (id == null || id == "") {
			return true;
		}
		if (date == null || date == "") {
			return true;
		}
		if (time == null || time == "") {
			return true;
		}
		if (lacid == null || lacid == "") {
			return true;
		}
		if (cellid == null || cellid == "") {
			return true;
		}
		return false;
	}
	
	public String getEntryValue() {
		return id + "," + date + " " + time;
	}
	
}
